package com.ybxx.asset.service.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.ybxx.asset.dao.HousingBuildingDao;
import com.ybxx.asset.model.Building;
import com.ybxx.asset.model.HousingBuilding;
import com.ybxx.asset.service.HousingBuildingService;
import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.dao.GenericDao;
import com.ybxx.core.service.impl.BaseServiceImpl;
import com.ybxx.core.web.paging.PagingBean;

public class HousingBuildingServiceImpl extends
		BaseServiceImpl<HousingBuilding> implements HousingBuildingService {
	private HousingBuildingDao housingBuildingDao;
	public HousingBuildingServiceImpl(HousingBuildingDao dao) {
		super(dao);
		this.housingBuildingDao=dao;
		// TODO Auto-generated constructor stub
	}
	public List<HousingBuilding> queryPage(HousingBuilding hb, QueryFilter filter) {
		String hql="from HousingBuilding b where 1=1 ";
		if(hb!=null && StringUtils.isNotEmpty(hb.getBancode())){
			hql+=" and b.bancode like '%"+hb.getBancode()+"%'";
		}
		if(hb!=null && StringUtils.isNotEmpty(hb.getBuildmonth())){
			hql+=" and b.buildmonth like '%"+hb.getBuildmonth()+"%'";
		}
		if(hb!=null && StringUtils.isNotEmpty(hb.getMdept())){
			hql+=" and b.mdept like '%"+hb.getMdept()+"%'";
		}
		
		
		return housingBuildingDao.findByHql(hql, null, filter.getPagingBean());
	}
	public List<HousingBuilding> exportExcel_Print(HousingBuilding hb) {
		String hql="from HousingBuilding b left join fetch b.company c where 1=1 ";
		if(hb!=null && StringUtils.isNotEmpty(hb.getBancode())){
			hql+=" and b.bancode like '%"+hb.getBancode()+"%'";
		}
		if(hb!=null && StringUtils.isNotEmpty(hb.getBuildmonth())){
			hql+=" and b.buildmonth like '%"+hb.getBuildmonth()+"%'";
		}
		if(hb!=null && StringUtils.isNotEmpty(hb.getMdept())){
			hql+=" and b.mdept like '%"+hb.getMdept()+"%'";
		}
		
		
		return housingBuildingDao.findByHql(hql, null);
	}
	@Override
	public HousingBuilding get(String id) {
		String hql="from HousingBuilding b left join fetch b.company c where hbid='"+id+"' ";
		return (HousingBuilding)housingBuildingDao.findUnique(hql, null);
	}
}
